
import actionType from "./actionType"
const initState={
    list:[]
}

const reducer =(state=initState,action)=>{
    const {type,payload}=action
    const {list}=state
    switch (type) {
        case actionType.SET_LIST:
            return{
                ...state,
                list:payload
            }
            case actionType.SET_ADD:
                const newList=list.find(item=>item.id===payload.id)
                if(newList){
                    newList.count++
                }else{
                    list.push({
                        ...payload,
                        count:'1'
                    })
                }
                console.log(newList)
                return{
                    ...state,
                    list:[...list]
                }
        default:
            return{
                ...state
            }
    }
}

export default reducer